package com.china08.yxyapi.service.mg.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.china08.yxyapi.entity.mg.homework.HomeworkQuesGroup;
import com.china08.yxyapi.repository.mg.homework.HomeworkQuesGroupRelQuesRepository;
import com.china08.yxyapi.repository.mg.homework.HomeworkQuesGroupRepository;
import com.china08.yxyapi.service.mg.HomeworkQuesGroupService;

@Service
public class HomeworkQuesGroupServiceImpl implements HomeworkQuesGroupService {

    @Autowired
    private HomeworkQuesGroupRepository homeworkQuesGroupRepository;

    @Autowired
    private HomeworkQuesGroupRelQuesRepository homeworkQuesGroupRelQuesRepository;

    @Override
    public void updateQuesCount(String groupId) {
        HomeworkQuesGroup homeworkQuesGroup = homeworkQuesGroupRepository.findById(groupId);
        if (homeworkQuesGroup != null) {
            Integer countInteger = homeworkQuesGroupRelQuesRepository.countByGroupId(groupId);
            homeworkQuesGroup.setQuesCount(countInteger);
            homeworkQuesGroupRepository.save(homeworkQuesGroup);
        }
    }
}
